optimise literalOsPath
authorJoey Hess <joeyh@joeyh.name>
Mon, 27 Jan 2025 19:54:24 +0000 (15:54 -0400)
committerJoey Hess <joeyh@joeyh.name>
Mon, 27 Jan 2025 20:36:29 +0000 (16:36 -0400)
Taking a ShortByteString and using OverloadedStrings should avoid it
being converted from a String.

The reason there is no IsString instance for OsPath is presumably the
bad behavior of IsString for ByteString on unicode btw. But
literalOsPath won't be used with unicode in git-annex.

Sponsored-by: unqueued
Annex/Magic.hs
Assistant/Install/Menu.hs
Build/DesktopFile.hs
Config/Files.hs
Utility/FreeDesktop.hs
Utility/OSX.hs
Utility/OsPath.hs
Utility/SshConfig.hs
Utility/Tmp/Dir.hs
Utility/Tor.hs

index eec8b404af8c94c666d9759322268f16f5b8463f..ade8efd6ead4d30776df62273ff1c3c6ab2245b0 100644 (file)
@@ -5,6 +5,7 @@
  - Licensed under the GNU AGPL version 3 or higher.
  -}
 
+{-# LANGUAGE OverloadedStrings #-}
 {-# LANGUAGE CPP #-}
 
 module Annex.Magic (
index 7308608bb4015e1fe5966feda02b3843a4d47578..04261838ef7a5173fd2ed9354b17f2c661816ade 100644 (file)
@@ -5,6 +5,7 @@
  - Licensed under the GNU AGPL version 3 or higher.
  -}
 
+{-# LANGUAGE OverloadedStrings #-}
 {-# LANGUAGE CPP #-}
 {-# OPTIONS_GHC -fno-warn-tabs #-}
 
index 3dd887d048ff055cd94c062b561d54b0997981c1..b69fd828542bffcae143dab2ad044db49aa5b86a 100644 (file)
@@ -6,6 +6,7 @@
  - Licensed under the GNU AGPL version 3 or higher.
  -}
 
+{-# LANGUAGE OverloadedStrings #-}
 {-# LANGUAGE CPP #-}
 {-# OPTIONS_GHC -fno-warn-tabs #-}
 
index fb0670bf391f0b4027779fd368796930e878b40c..14450fcc7256ae3ad1ca677910bb83d53ac745d3 100644 (file)
@@ -5,6 +5,7 @@
  - Licensed under the GNU AGPL version 3 or higher.
  -}
 
+{-# LANGUAGE OverloadedStrings #-}
 {-# OPTIONS_GHC -fno-warn-tabs #-}
 
 module Config.Files where
index 825954437725be622656f7eadd6690f07555a962..71ec3a3c7b395b634b259afabe385d1146a895cb 100644 (file)
@@ -10,6 +10,7 @@
  - License: BSD-2-clause
  -}
 
+{-# LANGUAGE OverloadedStrings #-}
 {-# OPTIONS_GHC -fno-warn-tabs #-}
 
 module Utility.FreeDesktop (
index 1f14d3092346d983c0733e1b2b650989daca0b53..1bcbe4c628b0a84e90dff3887407c6eccded50dd 100644 (file)
@@ -5,6 +5,7 @@
  - License: BSD-2-clause
  -}
 
+{-# LANGUAGE OverloadedStrings #-}
 {-# OPTIONS_GHC -fno-warn-tabs #-}
 
 module Utility.OSX (
@@ -18,7 +19,9 @@ import Common
 import Utility.UserInfo
 
 autoStartBase :: String -> OsPath
-autoStartBase label = literalOsPath "Library" </> literalOsPath "LaunchAgents" </> literalOsPath (label ++ ".plist")
+autoStartBase label = literalOsPath "Library" 
+       </> literalOsPath "LaunchAgents"
+       </> toOsPath label <> literalOsPath ".plist"
 
 systemAutoStart :: String -> OsPath
 systemAutoStart label = literalOsPath "/" </> autoStartBase label
index 28e3040841ecb3489fd563c4c9ea101a1eb7a16d..b487a2976d41cb395800e1542d24be7b6c2e5af8 100644 (file)
@@ -46,10 +46,6 @@ instance OsPathConv FilePath where
        toOsPath = toOsPath . toRawFilePath
        fromOsPath = fromRawFilePath . fromOsPath
 
-{- Used for string constants. -}
-literalOsPath :: String -> OsPath
-literalOsPath = toOsPath
-
 #ifdef WITH_OSPATH
 instance OsPathConv RawFilePath where
        toOsPath = bytesToOsPath . S.toShort
@@ -80,6 +76,10 @@ bytesFromOsPath = getPosixString . getOsString
 getSearchPath :: IO [OsPath]
 getSearchPath = map toOsPath <$> PB.getSearchPath
 
+{- Used for string constants. -}
+literalOsPath :: ShortByteString -> OsPath
+literalOsPath = bytesToOsPath
+
 #else
 {- When not building with WITH_OSPATH, use RawFilePath.
  -}
@@ -97,4 +97,7 @@ instance OsPathConv ShortByteString where
 
 unsafeFromChar :: Char -> Word8
 unsafeFromChar = fromIntegral . ord
+
+literalOsPath :: RawFilePath -> OsPath
+literalOsPath = id
 #endif
index 798a48148fb381e6b0409ac6ef52761108d1d841..e341b738944ef8378e7a665896505212ff062c7d 100644 (file)
@@ -5,6 +5,8 @@
  - License: BSD-2-clause
  -}
 
+{-# LANGUAGE OverloadedStrings #-}
+
 module Utility.SshConfig (
        SshConfig(..),
        Comment(..),
index fa61d30f5b0fbe509b7bd4ec2ec523daa1533d9b..d6448ef749b808eda468f86c3753d0c7ef4fc92c 100644 (file)
@@ -7,6 +7,7 @@
 
 {-# LANGUAGE CPP #-}
 {-# OPTIONS_GHC -fno-warn-tabs #-}
+{-# LANGUAGE OverloadedStrings #-}
 
 module Utility.Tmp.Dir (
        withTmpDir,
index 1696d7c3cf523a2f058b8744c7a6579db6cd3b2f..eeabbbae799c947d97447dfe431eccd200e130c2 100644 (file)
@@ -5,6 +5,8 @@
  - Licensed under the GNU AGPL version 3 or higher.
  -}
 
+{-# LANGUAGE OverloadedStrings #-}
+
 module Utility.Tor (
        OnionPort,
        OnionAddress(..),
@@ -143,7 +145,7 @@ hiddenServiceHostnameFile appname uid ident =
 hiddenServiceSocketFile :: AppName -> UserID -> UniqueIdent -> OsPath
 hiddenServiceSocketFile appname uid ident = 
        varLibDir </> toOsPath appname
-               </> toOsPath (show uid ++ "_" ++ ident) </> toOsPath "s"
+               </> toOsPath (show uid ++ "_" ++ ident) </> literalOsPath "s"
 
 -- | Parse torrc, to get the socket file used for a hidden service with
 -- the specified UniqueIdent.
@@ -155,7 +157,7 @@ getHiddenServiceSocketFile _appname uid ident =
        parse [] = Nothing
        parse (("HiddenServiceDir":hsdir:[]):("HiddenServicePort":_hsport:hsaddr:[]):rest)
                | "unix:" `isPrefixOf` hsaddr && hasident (toOsPath hsdir) =
-                       Just $ toOsPath $ drop (length "unix:") hsaddr
+                       Just $ toOsPath $ drop (length ("unix:" :: String)) hsaddr
                | otherwise = parse rest
        parse (_:rest) = parse rest